package com.gears_software.bbnetwork.datas.finders.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;

import com.alibaba.fastjson.JSON;
import com.gears_software.bbnetwork.datas.finders.IBBNetworkFinder;
import com.gears_software.bbnetwork.datas.finders.ProjectUrl;
import com.gears_software.bbnetwork.datas.models.AchieveBankIconUrls;
import com.gears_software.bbnetwork.datas.models.BaseJsonToModel;
import com.gears_software.bbnetwork.datas.models.CertificationModel;
import com.gears_software.bbnetwork.datas.models.CurrentBankInfoModel;
import com.gears_software.bbnetwork.datas.models.DrawHistoryModel;
import com.gears_software.bbnetwork.datas.models.MainModel;
import com.gears_software.bbnetwork.datas.models.RecommendRewardzModel;
import com.gears_software.bbnetwork.datas.models.ReportInfoModel;
import com.gears_software.bbnetwork.datas.models.ResultModel;
import com.gears_software.bbnetwork.datas.models.TixianCashModel;
import com.gears_software.bbnetwork.datas.models.UserModel;
import com.gears_software.common.net.HttpsUtil;
import com.gears_software.common.utils.versionupdate.VersionModel;

@EBean
public class IBBNetworkFinderImpl implements IBBNetworkFinder {
	
	@Bean
	ProjectUrl url;
	
	//获取验证码
	@Override
	public BaseJsonToModel getRegistCode(String mobilePhone, String UUID) {
		BaseJsonToModel res = new BaseJsonToModel();
		Map<String, String> params = new HashMap<String,String>();
		if(mobilePhone!=null){
			params.put("mobilePhone", mobilePhone);
		}
		if(UUID!=null){
			params.put("uniDeviceCode", UUID);
		}
		
		String json = HttpsUtil.httpsPost(url.getRegist(), params);
		if(json==null||json.equals("")){
			return res;
		}
		res = JSON.parseObject(json,BaseJsonToModel.class);
		return res;
	}

	//注册及登录
	@Override
	public ResultModel<UserModel>  getVerifyRegistCode(String mobilePhone,
			String uniDeviceCode, String verifyCode) {
		ResultModel<UserModel> res = new ResultModel<UserModel>();
		Map<String, String> params = new HashMap<String,String>();
		if(mobilePhone!=null){
			params.put("mobilePhone", mobilePhone);
		}
		if(uniDeviceCode!=null){
			params.put("uniDeviceCode", uniDeviceCode);
		}
		if(verifyCode!=null){
			params.put("verifyCode", verifyCode);
		}
		
		String json = HttpsUtil.httpsPost(url.getVerifyRegistCode(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel jsonModel = JSON.parseObject(json,BaseJsonToModel.class);
		if(jsonModel.getReturnData()!=null){
			UserModel userModel = JSON.parseObject(jsonModel.getReturnData().toString(),UserModel.class);
			res.setResObj(userModel);
		}
		res.setMessage(jsonModel.getResultMessage());
		res.setReturnCode(jsonModel.getResultCode());
		return res;
	}
	
	//直接登录
	@Override
	public ResultModel<UserModel> getLogin(String mobilePhone,
			String uniDeviceCode) {
		ResultModel<UserModel> res = new ResultModel<UserModel>();
		Map<String, String> params = new HashMap<String, String>();
		if(mobilePhone!=null){
			params.put("mobilePhone", mobilePhone);
		}
		if(uniDeviceCode!=null){
			params.put("uniDeviceCode", uniDeviceCode);
		}
		
		String json = HttpsUtil.httpsPost(url.getLogin(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel bjt = JSON.parseObject(json,BaseJsonToModel.class);
		if(bjt.getReturnData()!=null){
			UserModel userModel = JSON.parseObject(bjt.getReturnData().toString(),UserModel.class);
			res.setResObj(userModel);
			
		}
		res.setMessage(bjt.getResultMessage());
		res.setReturnCode(bjt.getResultCode());
		return res;
	}

	//提交报单
	@Override
	public ResultModel<String> getApply(String userId, String projectName) {
		ResultModel<String> res = new ResultModel<String>();
		Map<String, String> params =new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		if(projectName!=null){
			params.put("projectName",projectName);
		}
		String json = HttpsUtil.httpsPost(url.getApply(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel model = JSON.parseObject(json,BaseJsonToModel.class);
		res.setMessage(model.getResultMessage());
		res.setReturnCode(model.getResultCode());
		return res;
	}

	//报单列表
	@Override
	public ResultModel<List<ReportInfoModel>> getBaodanList(String userId,String pageNum) {
		ResultModel<List<ReportInfoModel>> res = new ResultModel<List<ReportInfoModel>>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		String data = sdf.format(new Date());
		if(pageNum!=null){
			params.put("pageNum", pageNum);
		}
		params.put("pageSize", "10");
		
		String json = HttpsUtil.httpsPost(url.getBaodanList(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel jsonModel = JSON.parseObject(json,BaseJsonToModel.class);
		if(jsonModel.getReturnData()!=null){
			List<ReportInfoModel> info = JSON.parseArray(jsonModel.getReturnData().toString(),ReportInfoModel.class);
			res.setResObj(info);
		}
		res.setMessage(jsonModel.getResultMessage());
		res.setReturnCode(jsonModel.getResultCode());
		return res;
	}

	//第一次设置密码
	@Override
	public ResultModel<String> getSetCashPws(String userId, String cashPassword) {
		ResultModel<String> res = new ResultModel<String>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		if(cashPassword!=null){
			params.put("cashPassword", cashPassword);
		}
		String json = HttpsUtil.httpsPost(url.getSetCashPwd(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel model = JSON.parseObject(json,BaseJsonToModel.class);
		res.setMessage(model.getResultMessage());
		res.setReturnCode(model.getResultCode());
		return res;
	}

	//修改密码
	@Override
	public ResultModel<String> getUpdateCashPws(String userId,
			String oldCashPassword, String newCashPassword) {
		ResultModel<String> res = new ResultModel<String>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		if(oldCashPassword!=null){
			params.put("oldCashPassword", oldCashPassword);
		}
		if(newCashPassword!=null){
			params.put("newCashPassword", newCashPassword);
		}
		String json = HttpsUtil.httpsPost(url.getUpdateCashPwd(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel model = JSON.parseObject(json,BaseJsonToModel.class);
		res.setMessage(model.getResultMessage());
		res.setReturnCode(model.getResultCode());
		return res;
	}

	//可提现金额
	@Override
	public ResultModel<TixianCashModel> getTixianInfo(String userId) {
		ResultModel<TixianCashModel> res = new ResultModel<TixianCashModel>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		String json = HttpsUtil.httpsPost(url.getTixianInfo(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel model = JSON.parseObject(json,BaseJsonToModel.class);
		if(model.getReturnData()!=null){
			TixianCashModel tixian = JSON.parseObject(model.getReturnData().toString(),TixianCashModel.class);
			res.setResObj(tixian);
		}
		res.setMessage(model.getResultMessage());
		res.setReturnCode(model.getResultCode());
		return res;
	}

	//获取银行列表
	@Override
	public ResultModel<List<AchieveBankIconUrls>> getYinhangList(String userId) {
		ResultModel<List<AchieveBankIconUrls>> res = new ResultModel<List<AchieveBankIconUrls>>();
		Map<String,String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		String json = HttpsUtil.httpsPost(url.getYinhangList(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel model = JSON.parseObject(json,BaseJsonToModel.class);
		if(model.getReturnData()!=null){
			List<AchieveBankIconUrls> list = JSON.parseArray(model.getReturnData().toString(), AchieveBankIconUrls.class);
			res.setResObj(list);
		}
		res.setMessage(model.getResultMessage());
		res.setReturnCode(model.getResultCode());
		return res;
	}

	//绑定银行卡
	@Override
	public ResultModel<String> getBindCard(String userId, String cardNo,
			String bankName, String depositBankName) {
		ResultModel<String> res = new ResultModel<String>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		if(cardNo!=null){
			params.put("cardNo", cardNo);
		}
		if(bankName!=null){
			params.put("bankName", bankName);
		}
		if(depositBankName!=null){
			params.put("depositBankName", depositBankName);
		}
		String json = HttpsUtil.httpsPost(url.getBindCard(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel jsonM = JSON.parseObject(json,BaseJsonToModel.class);
		res.setMessage(jsonM.getResultMessage());
		res.setReturnCode(jsonM.getResultCode());
		return res;
	}

	//获取银行卡信息
	@Override
	public ResultModel<List<CurrentBankInfoModel>> getCardInfo(String userId) {
		ResultModel<List<CurrentBankInfoModel>> res = new ResultModel<List<CurrentBankInfoModel>>();
		List<CurrentBankInfoModel> list = new ArrayList<CurrentBankInfoModel>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		String json = HttpsUtil.httpsPost(url.getCardInfo(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel jsonModel = JSON.parseObject(json,BaseJsonToModel.class);
		if(jsonModel.getReturnData()!=null){
			
			CurrentBankInfoModel model = JSON.parseObject(jsonModel.getReturnData().toString(),CurrentBankInfoModel.class);
			list.add(model);
			res.setResObj(list);
		}
		res.setMessage(jsonModel.getResultMessage());
		res.setReturnCode(jsonModel.getResultCode());
		return res;
	}

	//获取认证信息
	@Override
	public ResultModel<CertificationModel> getRealNameAuth(String userId) {
		ResultModel<CertificationModel> res = new ResultModel<CertificationModel>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		String json = HttpsUtil.httpsPost(url.getRealNameAuth(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel jsonModel = JSON.parseObject(json,BaseJsonToModel.class);
		if(jsonModel.getReturnData()!=null){
			CertificationModel model = JSON.parseObject(jsonModel.getReturnData().toString(),CertificationModel.class);
			res.setResObj(model);
		}
		res.setMessage(jsonModel.getResultMessage());
		res.setReturnCode(jsonModel.getResultCode());
		return res;
	}

	//实名认证
	@Override
	public ResultModel<String> getAudit(String userId, String realName,
			String company, String IDCardNo) {
		ResultModel<String> res = new ResultModel<String>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		if(realName!=null){
			params.put("realName", realName);
		}
		if(company!=null){
			params.put("company", company);
		}
		if(IDCardNo!=null){
			params.put("IDCardNo", IDCardNo);
		}
		String json = HttpsUtil.httpsPost(url.getAudit(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel jsonModel = JSON.parseObject(json,BaseJsonToModel.class);
		res.setMessage(jsonModel.getResultMessage());
		res.setReturnCode(jsonModel.getResultCode());
		return res;
	}

	//银行卡解绑
	@Override
	public ResultModel<String> getDeleteCard(String userId) {
		ResultModel<String> res = new ResultModel<String>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		String json = HttpsUtil.httpsPost(url.getDeleteCard(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel jsonModel = JSON.parseObject(json,BaseJsonToModel.class);
		res.setMessage(jsonModel.getResultMessage());
		res.setReturnCode(jsonModel.getResultCode());
		return res;
	}

	//提现
	@Override
	public ResultModel<String> getTixian(String userId, String drawAmount,
			String cashPassword) {
		ResultModel<String> res = new ResultModel<String>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		if(drawAmount!=null){
			params.put("drawAmount", drawAmount);
		}
		if(cashPassword!=null){
			params.put("cashPassword", cashPassword);
		}
		String json = HttpsUtil.httpsPost(url.getTixian(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel jsonModel = JSON.parseObject(json,BaseJsonToModel.class);
		res.setMessage(jsonModel.getResultMessage());
		res.setReturnCode(jsonModel.getResultCode());
		return res;
	}

	//删除文件接口
	@Override
	public ResultModel<String> getDeleteFile(String userId,
			String originalFileInformationId) {
		ResultModel<String> res = new ResultModel<String>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		if(originalFileInformationId!=null){
			params.put("originalFileInformationId", originalFileInformationId);
		}
		String json = HttpsUtil.httpsPost(url.getDeleteFile(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel jsonModel = JSON.parseObject(json,BaseJsonToModel.class);
		res.setMessage(jsonModel.getResultMessage());
		res.setReturnCode(jsonModel.getResultCode());
		return res;
	}
	
	//提现历史
	@Override
	public ResultModel<List<DrawHistoryModel>> getTixianList(String userId,String pageNum) {
		ResultModel<List<DrawHistoryModel>> res = new ResultModel<List<DrawHistoryModel>>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		if(pageNum!=null){
			params.put("pageNum", pageNum);
		}
		params.put("pageSize", "10");
		String json = HttpsUtil.httpsPost(url.getTixianList(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel jsonModel = JSON.parseObject(json,BaseJsonToModel.class);
		if(jsonModel.getReturnData()!=null){
			List<DrawHistoryModel> list = JSON.parseArray(jsonModel.getReturnData().toString(),DrawHistoryModel.class);
			res.setResObj(list);
		}
		res.setMessage(jsonModel.getResultMessage());
		res.setReturnCode(jsonModel.getResultCode());
		return res;
	}
	
	//获取首页数据
	@Override
	public ResultModel<MainModel> getHomeData() {
		ResultModel<MainModel> res = new ResultModel<MainModel>();
		String json = HttpsUtil.httpsPost(url.getHome());
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel model = JSON.parseObject(json,BaseJsonToModel.class);
		res.setMessage(model.getResultMessage());
		res.setReturnCode(model.getResultCode());
		if(model.getReturnData()!=null&&!model.getReturnData().equals("")){
			MainModel mainModel = JSON.parseObject(model.getReturnData().toString(),MainModel.class);
			res.setResObj(mainModel);
		}
		return res;
	}

	//获取推荐码
	@Override
	public ResultModel<String> getRecommendCode(String userId) {
		ResultModel<String> res = new ResultModel<String>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		String json = HttpsUtil.httpsPost(url.getRecommend(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel jsonModel = JSON.parseObject(json,BaseJsonToModel.class);
		res.setMessage(jsonModel.getResultMessage());
		res.setReturnCode(jsonModel.getResultCode());
		res.setResObj(jsonModel.getRecommendCode());
		return res;
	}

	//获取推荐奖励数据
	@Override
	public ResultModel<List<RecommendRewardzModel>> getRecommendRewardzList(
			String userId, String pageNum) {
		ResultModel<List<RecommendRewardzModel>> res = new ResultModel<List<RecommendRewardzModel>>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		if(pageNum!=null){
			params.put("pageNum", pageNum);
		}
		params.put("pageSize", "10");
		String json = HttpsUtil.httpsPost(url.getRecommendRewardzList(),params);
		if(json==null||json.equals("")){
			return res;
		}
		
		BaseJsonToModel jsonModel = JSON.parseObject(json,BaseJsonToModel.class);
		if(jsonModel.getReturnData()!=null){
			List<RecommendRewardzModel> list = JSON.parseArray(jsonModel.getReturnData().toString(), RecommendRewardzModel.class);
			res.setResObj(list);
		}
		res.setMessage(jsonModel.getResultMessage());
		res.setReturnCode(jsonModel.getResultCode());
		return res;
	}

	//提交推荐码
	@Override
	public ResultModel<String> getSubmitCode(String userId, String recommendCode) {
		ResultModel<String> res = new ResultModel<String>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		if(recommendCode!=null){
			params.put("recommendCode", recommendCode);
		}
		String json = HttpsUtil.httpsPost(url.getSubmitRecommendRewardzCode(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel jsonModel = JSON.parseObject(json,BaseJsonToModel.class);
		res.setMessage(jsonModel.getResultMessage());
		res.setReturnCode(jsonModel.getResultCode());
		return res;
	}

	//跳过推荐码
	@Override
	public ResultModel<String> getSkipCode(String userId) {
		ResultModel<String> res = new ResultModel<String>();
		Map<String, String> params = new HashMap<String, String>();
		if(userId!=null){
			params.put("userId", userId);
		}
		String json = HttpsUtil.httpsPost(url.getSkipCode(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel jsonModel = JSON.parseObject(json,BaseJsonToModel.class);
		res.setMessage(jsonModel.getResultMessage());
		res.setReturnCode(jsonModel.getResultCode());
		
		return res;
	}

	//获取版本信息
	@Override
	public ResultModel<VersionModel> getVersion() {
		ResultModel<VersionModel> res = new ResultModel<VersionModel>();
		Map<String, String> params = new HashMap<String, String>();
		params.put("type", "1");
		String json = HttpsUtil.httpsPost(url.getVersion(), params);
		if(json==null||json.equals("")){
			return res;
		}
		BaseJsonToModel jsonModel = JSON.parseObject(json,BaseJsonToModel.class);
		res.setMessage(jsonModel.getResultMessage());
		res.setReturnCode(jsonModel.getResultCode());
		if(jsonModel.getReturnData()!=null&&!jsonModel.getReturnData().equals("")){
			VersionModel model = JSON.parseObject(jsonModel.getReturnData().toString(),VersionModel.class);
			res.setResObj(model);
		}
		return res;
	}

}
